package com.bsoft.gol.hcb.dao.prescriptionCirculation;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import pcn.prescriptionCirculation.OdsOrderExpenseRecord;

import java.util.List;

/**
 * @description: 订单医技记录表
 * @author: chenJij@bsoft.com.cn
 * @date: 2021/8/30
 */
public abstract class OdsOrderExpenseRecordDAO extends HibernateSupportDelegateDAO<OdsOrderExpenseRecord> {
    public OdsOrderExpenseRecordDAO() {
        this.setKeyField("orderExpenseId");
    }

    @DAOMethod(sql = "from OdsOrderExpenseRecord where orderId =:orderId")
    public abstract List<OdsOrderExpenseRecord> findByOrderId(@DAOParam("orderId")String orderId);

    @DAOMethod(sql = "from OdsOrderExpenseRecord where orderId =:orderId and expenseId=:expenseId")
    public abstract OdsOrderExpenseRecord getOdsOrderExpenseRecordByOrderIdAndExpenseId(@DAOParam("orderId")String orderId,@DAOParam("expenseId")String expenseId);

    @DAOMethod(sql = "select count(1) from OdsOrderExpenseRecord a,OdsPrescriptionOrder b  where a.orderId = b.orderId and  a.organizationId =:localOrgId and a.expenseIdSource =:expenseIdSource and b.payStatus in ('0','1') and b.deleteFlag='0' ")
    public abstract long getPayedCount(@DAOParam("localOrgId")String orgId,@DAOParam("expenseIdSource")String expenseIdSource);

    @DAOMethod(sql = "select count(1) from OdsOrderExpenseRecord a,OdsPrescriptionOrder b  where a.orderId = b.orderId and  a.organizationId =:localOrgId and a.expenseId =:expenseId and b.payStatus in ('0','1') and b.deleteFlag='0' ")
    public abstract long getPayedCountByExpenseId(@DAOParam("localOrgId")String orgId,@DAOParam("expenseId")String expenseId);

    @DAOMethod(sql = "select count(1) from OdsOrderExpenseRecord a,OdsPrescriptionOrder b  where a.orderId = b.orderId and  a.organizationId =:localOrgId and a.expenseId in:expenseIdList and b.payStatus in ('0','1') and b.deleteFlag='0' ")
    public abstract long getPayedCountByExpenseIdList(@DAOParam("localOrgId")String orgId,@DAOParam("expenseIdList")List<String> expenseIdList);


}
